/***************************************************************************
 *   Copyright (C) 2005 by xihe						   *
 *   xihels@163.com							   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "CycloneMenu.h"
#include "MainWindow.h"
#include "pixmaps.h"

#include "config.h"
#include <gtkmmconfig.h>
#if GTKMM_MAJOR_VERSION==2 && GTKMM_MINOR_VERSION>2
#define GMM_GTKMM_22_24(a,b) b
#else //gtkmm 2.2
#define GMM_GTKMM_22_24(a,b) a
#endif //

#include <gtkmm/image.h>
#include <gtkmm/imagemenuitem.h>
#include <gtkmm/menuitem.h>

#include <gtk/gtkimagemenuitem.h>

BuddyMenu::BuddyMenu(MainWindow& wnd)
{
    Gtk::Image* image = getImage("menu_chat.png");
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("聊天(_C)", *image));
    Gtk::ImageMenuItem* itemChat = (Gtk::ImageMenuItem *)&this->items().back();

    image = getImage("menu_log.png");
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("日志(_L)", *image));
    Gtk::ImageMenuItem* itemLog = (Gtk::ImageMenuItem*)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-info")));
    //it's strange that gtk-info does'nt work
    Gtk::ImageMenuItem* itemInfo = (Gtk::ImageMenuItem*)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::SeparatorElem());

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete")));
    Gtk::ImageMenuItem* itemRemove = (Gtk::ImageMenuItem*)&this->items().back();

    this->show_all();


    itemChat->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_buddyChat_activate), false);
    itemLog->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_buddyLog_activate), false);
    itemInfo->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_buddyInfo_activate), false);
    itemRemove->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_buddyRemove_activate), false);

}

GroupMenu::GroupMenu(MainWindow& wnd)
{
    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-new")));
    Gtk::ImageMenuItem* itemNew = (Gtk::ImageMenuItem *)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete")));
    Gtk::ImageMenuItem* itemRemove = (Gtk::ImageMenuItem *)&this->items().back();

    this->show_all();


    itemNew->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_groupNew_activate), false);
    itemRemove->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_groupRemove_activate), false);
}

UserMenu::UserMenu(MainWindow& wnd)
{
    Gtk::Image* image = getImage("menu_online.png");
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("在线(_O)", *image));
    Gtk::ImageMenuItem* itemOnline = (Gtk::ImageMenuItem *)&this->items().back();

    image = getImage("menu_away.png");
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("离开(_A)", *image));
    Gtk::ImageMenuItem* itemAway = (Gtk::ImageMenuItem *)&this->items().back();

    image = getImage("menu_hidden.png");
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("隐身(_H)", *image));
    Gtk::ImageMenuItem* itemHidden = (Gtk::ImageMenuItem *)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::SeparatorElem());

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-info")));
    Gtk::ImageMenuItem* itemInfo = (Gtk::ImageMenuItem *)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::SeparatorElem());

    image = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-quit"), Gtk::IconSize(1)));
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("退出(_E)", *image));
    Gtk::ImageMenuItem* itemExit = (Gtk::ImageMenuItem *)&this->items().back();

    image = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-new"), Gtk::IconSize(1)));
    this->items().push_back(Gtk::Menu_Helpers::ImageMenuElem("登录(_L)", *image));
    Gtk::ImageMenuItem* itemLogin = (Gtk::ImageMenuItem *)&this->items().back();
    
    this->show_all();


    itemOnline->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userOnline_activate), false);
    itemAway->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userAway_activate), false);
    itemHidden->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userHidden_activate), false);
    itemInfo->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userInfo_activate), false);
    itemExit->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userExit_activate), false);
    itemLogin->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_userNew_activate), false);

}


SystemMenu::SystemMenu(MainWindow& wnd)
{
    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-about")));
    Gtk::ImageMenuItem* itemAbout = (Gtk::ImageMenuItem *)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-find")));
    Gtk::ImageMenuItem* itemFind = (Gtk::ImageMenuItem *)&this->items().back();

    this->items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-preferences")));
    Gtk::ImageMenuItem* itemPrefer = (Gtk::ImageMenuItem *)&this->items().back();
    
    this->show_all();


    itemFind->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_findBuddy_activate), false);
    itemAbout->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_about_activate), false);
    itemPrefer->signal_activate().connect(
	    sigc::mem_fun(wnd, &MainWindow::on_setPrefer_activate), false);
}

